package fhp.hlhj.giantfold.activity.sharejz

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.adapter.FriendsEfAdp
import fhp.hlhj.giantfold.interfaces.IFriendsEf
import fhp.hlhj.giantfold.javaBean.FriendsEFBean
import fhp.hlhj.giantfold.presenter.FriendsEfPresenter
import fhp.hlhj.giantfold.utils.MyUtils
import kotlinx.android.synthetic.main.activity_share_friends_aty.*

class ShareFriendsAty : BaseActivity(),IFriendsEf {
    private val datas=ArrayList<FriendsEFBean.DataBean>()
    private lateinit var adp:FriendsEfAdp
    private lateinit var presenter:FriendsEfPresenter
    private val page=0
    override fun getContentId(): Int = R.layout.activity_share_friends_aty

    override fun initView() {
        presenter= FriendsEfPresenter(this)
        adp= FriendsEfAdp(this,datas)

        presenter.setListView()


        val params = HttpParams()
        params.put("client","android")
        params.put("page",page)
        params.put("user_id",Contents.userId)
        presenter.getFriendef(params)
    }

    override fun initListener() {
        super.initListener()
        btExit.setOnClickListener {
            finish()
        }
    }

    override fun showLoading() {
        loadingDialog.show()
    }

    override fun setListView() {
        listView.emptyView=empty_view
        listView.adapter=adp
    }

    override fun onResp(friendsEFBean: FriendsEFBean) {
        loadingDialog.dismiss()
        if (friendsEFBean.code==200){

            tvFriendsTotal.text=MyUtils.formatDouble(friendsEFBean.sum_actual_amount.toDouble(),2)
            tvFriendsNum.text=friendsEFBean.invited_number.toString()
            datas.addAll(friendsEFBean.data)
            adp.notifyDataSetChanged()
        }
    }
}
